package someTestExcemple.thread;

import java.util.concurrent.Callable;

//线程创建实现方式3
//实现Callable（有返回值的任务）接口，重写call方法，返回值是线程执行完毕后的结果
public class MyCallable1 implements Callable<String> {
    private int n;
    public MyCallable1(int n) {
        this.n = n;
    }
    @Override
    public String call() throws Exception {
        int sum = 0;
        for(int i = 1; i <= n; i++) {
            sum += i;
        }
        return "求出了1-"+ n + "的和为：" + sum;
    }

}
